<html>
<head>
<title>Math.uuid() Test</title>
<style>
body {font-family:sans-serif; font-size: 10pt;}
sup {
}
table {border-collapse:collapse; border-spacing: 0px;}
td {font-family: monospace; border: solid 1px #ccc; padding: 0px 10px;}
</style>
<script src="/Tools/JSLitmus/JSLitmus.js"></script>
<script src="Math.uuid.js"></script>
<script>
Number.prototype.toSciString = function() {
  if (this < 1e6) return this;
  var e = Math.floor(Math.log(this)/Math.log(10));
  return Math.round(this/Math.pow(10,e-1))/10 + 'x10<sup>' + e + '</sup>';
}

function writeUUIDTable() {
  var ARGS = [
    // No args (show what rfc4122 id looks like)
    [],
    // No args (show what rfc4122 id looks like)
    'uuidCompact',
    'uuidFast',
    //  Two args (show what base 2, 10, and 16 uuids look like)
    [10,2], [10,10], [10,16],
    // One arg (show how many possible uuids there are for each length)
    [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14],
    [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26],
    [27], [28], [29], [30], [31], [32], [33], [34], [35]
  ];

  var h = [];
  while (ARGS.length > 0) {
    var x = ARGS.shift(), args = (typeof(x) == 'string') ? [] : x;
    var method = (typeof(x) == 'string') ? x : 'uuid';
    var length = args[0] || 0, radix = args[1] || 62;
    var prob = length ? Math.pow(radix, length) : Math.pow(2, 122);
    var uuid = Math[method](args[0], args[1]);

    h.push('<tr>');
    h.push('<td>Math.' + method + '(' + args.join(',') + ')</td>');
    h.push('<td>' + uuid + '</td>');
    h.push('<td style="text-align:right">' + prob.toSciString() + '</td>');
    h.push('<tr>');
  }
  document.write(h.join('\n'));
}
</script>
</head>

<body>

<div style="float:right; border: solid 1px #ccc; padding: 10px; margin:10px">
<h2>Performance Tests</h2>
<div id="jslitmus_container"></div>
<script>
JSLitmus.test('Math.uuid()', function(count) {while (count--) Math.uuid();});
JSLitmus.test('Math.uuidCompact()', function(count) {while (count--) Math.uuidCompact();});
JSLitmus.test('Math.uuidFast()', function(count) {while (count--) Math.uuidFast();});
JSLitmus.test('Math.uuid(10)', function(count) {while (count--) Math.uuid(10);});
JSLitmus.test('Math.uuid(20)', function(count) {while (count--) Math.uuid(20);});
</script>
</div>

<h2>Math.uuid.js Test</h2>
<table>
  <tr>
    <th>command</th>
    <th>returned uuid</th>
    <th>possible uuids</th>
  </tr>
  <script>writeUUIDTable()</script>
</table>
</body>
</html>
